<?php
/**
 * Copyright (c) 2006-2007, Julien PORTALIER
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright    Copyright (c) 2006-2007, Julien PORTALIER
 * @link         http://featherphp.googlecode.com/
 * @license      http://www.opensource.org/licenses/mit-license.php The MIT License
 */

/**
 * Base framework's singleton object.
 * 
 * @deprecated Until PHP 5.3.x or PHP 6
 */
abstract class BaseSingleton
{
	protected static $_instance;
	
	protected function __construct()
	{
	}
	
	function instance($c=null)
	{
		if (is_null(self::$_instance))
		{
			if (is_null($c)) $c = __CLASS__;
			self::$_instance = new $c;
		}
		return self::$_instance;
	}
	
	function __clone()
	{
		trigger_error("Cloning this object is forbidden.", E_USER_ERROR);
	}
}

/**
 * Base framework's object for callbacks.
 */
abstract class BaseCallback
{
	private $_callbacks = array();
	
	/**
	 * Binds a callback to a certain action.
	 */
	function bindCallback($action, $plugin=null, $func=null)
	{
		$func = empty($func) ? $action : $func;
		$this->_callbacks[$action][$plugin] = $func;
	}
	
	/**
	 * Launch registered callbacks for a specific action.
	 */
	function callback($action, $arg=null)
	{
		# no one registered
		if (!isset($this->_callbacks[$action]))
			return;
		
		# call registered
		foreach($this->_callbacks[$action] as $plugin => $func)
		{
			if (empty($plugin))
				$this->$func(&$arg);
			else
				$this->$plugin->$func(&$arg);
		}
	}
}
?>